package com.zhiyou.hospital.ssh.service.impl;

import com.zhiyou.hospital.ssh.dao.IUserDao;
import com.zhiyou.hospital.ssh.model.UserModel;
import com.zhiyou.hospital.ssh.result.LoginResult;
import com.zhiyou.hospital.ssh.service.IUserService;
import com.zhiyou.hospital.ssh.util.MD5Utils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Created by zhouyanchao on 2017/10/17.
 * Descr:
 */
@Service
public class UserServiceImpl extends BaseServiceImpl<UserModel> implements IUserService {

	@Autowired
	IUserDao userDao;

	@Override
	public LoginResult login(String name, String pwd) {

		UserModel userModel = userDao.getUserByLoginName(name);

		LoginResult result = new LoginResult();

		if(userModel==null){
			result.setSuccess(false);
			result.setMessage("用户不存在");
			return result;
		}

		//判断密码
		System.out.println(MD5Utils.getMd5Simple(pwd));
		if(userModel.getLoginPwd().equals(MD5Utils.getMd5Simple(pwd))){
			result.setSuccess(true);
			result.setUserModel(userModel);
		}else{
			result.setSuccess(false);
			result.setMessage("登录密码错误");
		}

		return result;
	}
}
